import request from '@/utils/request';

const getToken = () => localStorage.getItem('token');

export const getChatHistory = async (sender, receiver,classId) => {
    try {
        const token = getToken();
        const headers = {
            isToken: true,
            repeatSubmit: false
        };
        if (token) {
            headers['Authorization'] = `Bearer ${token}`;
        }
        const response = await request({
            url: `/chatmessage/chathistory?sender=${sender}&receiver=${receiver}&classId=${classId}`,
            headers,
            method: 'get',
            withCredentials: true
        });
        console.log('请求聊天历史记录返回数据：', response);
        return response;
    } catch (error) {
        console.error('请求聊天历史记录失败:', error);
        throw error;
    }
};